package com.project.web.controller.system;

import com.project.common.base.AjaxResult;
import com.project.common.base.TableDataInfo;
import com.project.system.service.IGoodsInfoService;
import com.project.user.domain.UserOrder;
import com.project.user.service.IUserAddressService;
import com.project.user.service.IUserOrderService;
import com.project.web.controller.common.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单列 信息操作处理
 *
 * @author administrator
 * @date 2021-02-23
 */
@Controller
@RequestMapping("/system/userOrder")
public class SystemOrderController extends BaseController {
    private String prefix = "system/order";

    @Autowired
    private IUserOrderService userOrderService;
    @Autowired
    private IGoodsInfoService goodsInfoService;
    @Autowired
    private IUserAddressService userAddressService;

    /**
     * 跳转用户订单页面
     *
     * @return
     */
    @RequiresPermissions("system:userOrder:view")
    @GetMapping()
    public String userOrder() {
        return prefix + "/userOrder";
    }

    /**
     * 跳转订单详情页面
     *
     * @param orderId
     * @param modelMap
     * @return
     */
    @GetMapping("/detail/{orderId}")
    public String userOrder(@PathVariable("orderId") Long orderId, ModelMap modelMap) {
        modelMap.put("order", userOrderService.selectUserOrderById(orderId));
        return prefix + "/orderDetail";
    }

    /**
     * 跳转编辑订单页面
     *
     * @param orderId
     * @param modelMap
     * @return
     */
    @GetMapping("/edit/{orderId}")
    public String edit(@PathVariable("orderId") Long orderId, ModelMap modelMap) {
        modelMap.put("order", userOrderService.selectUserOrderById(orderId));
        return prefix + "/edit";
    }

    /**
     * 查询订单
     *
     * @param userOrder
     * @param mmap
     * @return
     */
    @RequiresPermissions("system:userOrder:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserOrder userOrder, ModelMap mmap) {
        if (!this.getUser().isSuperAdmin()) {
            userOrder.setUserId(this.getUserId());
        }
        startPage();
        List<UserOrder> orderList = userOrderService.selectSystemOrderList(userOrder);
        return getDataTable(orderList);
    }

    /**
     * 修改保存订单列
     *
     * @param userOrder
     * @return
     */
    @RequiresPermissions("system:userOrder:editStatus")
    @PostMapping("/editStatus")
    @ResponseBody
    public AjaxResult editStatus(UserOrder userOrder) {
        return toAjax(userOrderService.updateUserOrder(userOrder));
    }


}
